<?php
$_setting_battle = new battles_controller();
$_setting_battle_item = new battles_item_controller();
if(isset($_GET['s'])) {$_SESSION['search'] = ''; header("Location:../backend/index.php?action=battles&page=1&row=5");}
if ($_POST['search'] == 'Search'){
    $_SESSION['search'] = $_POST['txt_search'];
}
if ($_GET['action'] == 'battles' && $_GET['do'] == 'del') {
    $id = $_GET['id'];
    $_setting_battle->deleteBattlesbyId($id);
}
if($_GET['action'] == 'battles' && $_GET['do_item'] == 'del_item')
{
    $id_bt = $_GET['id_bt'];
    $_setting_battle_item->deleteBattlesbyId($id_bt);
}
if (isset($_GET['action']) && ((isset($_GET['do'])) && ($_GET['do'] == 'add' || $_GET['do'] == 'edit'))) { 
    $width = 0;        $color = ""; $message = "";
    $titlevalue = "";
    $subtitlevalue = "";
    $startvotevalue = "";
    $maxvotevalue = "";
    $input_id = "";
	$titleInfo = "";
	$subtitleInfor = "";
	$startvoteInfo = "";
	$maxvoteInfo = "";
	$selected_ac_yes = "";
	$selected_ac_no = "";
	$selected_image = "";
	$selected_video = "";
    $selected_entertainment = "";
    $selected_music = "";
    $selected_sport = "";
	$class_input_title = "inp-form";
	$class_input_sub = "inp-form";
	$class_input_code_start = "inp-form";
	$class_input_code = "inp-form";
    $disable_select_type_battles = "";
    if ($_GET['do'] == 'add')$page_heading = "Add New Battles"; else $page_heading = "Edit Battles";
    
    if(isset($_POST['submit'])){
        $width = 100;
        if($_GET['do'] == 'add'){
            if(($_POST['txt_start_vote'] >= $_POST['txt_maxvote']) || (!$_setting_battle->validateTitle($_POST['txt_title'])) || (!$_setting_battle->validateTitle($_POST['txt_subtitle'])) || (!$_setting_battle->validateStartVote($_POST['txt_start_vote'])) || (!$_setting_battle->validateMaxVote($_POST['txt_maxvote']))){
                $color = "red";
                $input_id = "";
                $titlevalue = $_POST['txt_title'];
                $subtitlevalue = $_POST['txt_subtitle'];
                $startvotevalue = $_POST['txt_start_vote'];
                $maxvotevalue = $_POST['txt_maxvote'];
                if($_POST['active']== 'Yes') $selected_ac_yes = "selected='selected'"; else $selected_ac_no = "selected='selected'";
                if($_POST['battle_type']== 'Image') $selected_image = "selected='selected'"; else $selected_video = "selected='selected'";
                if($_POST['battle_category']=='entertainment') $selected_entertainment = "selected='selected'"; elseif($_POST['battle_category']=='music') $selected_music = "selected='selected'"; else  $selected_sport = "selected='selected'";
                if ($_GET['do'] == 'add'){ $message = "Add battle Failed !"; }else{ $message = "Edit Battle Failed !";}
                if(!$_setting_battle->validateTitle($_POST['txt_title'])){ $titleInfo = "field must more than 3 letters!"; $class_input_title = "inp-form-error"; }
                if(!$_setting_battle->validateTitle($_POST['txt_subtitle'])){ $subtitleInfor = " field must more than 3 letters !"; $class_input_sub = "inp-form-error"; }
                if($_POST['txt_maxvote'] <= $_POST['txt_start_vote']) {$maxvoteInfo = "Max Vote must greater than Start Vote";$startvoteInfo = "Start Vote must less than Max Vote";$class_input_code_start = "inp-form-error"; $class_input_code = "inp-form-error"; }
                if(!$_setting_battle->validateStartVote($_POST['txt_start_vote'])){ $startvoteInfo = "Start Vote must number and 4 digit !"; $class_input_code_start = "inp-form-error"; }
                if(!$_setting_battle->validateMaxVote($_POST['txt_maxvote'])){ $maxvoteInfo = "Max Vote must number and 5 digit !"; $class_input_code = "inp-form-error"; } 
            }else{
                 $color = "green";
                    $date_create = date("Y,m,d");
                    $battle = new battles('', $_POST['txt_title'], $_POST['txt_subtitle'], $_POST['battle_type'], $_POST['active'], $_POST['txt_maxvote'], $_POST['txt_start_vote'], $date_create, '',$_POST['category']);
                    $_setting_battle->addBattles($battle);
                    $message = "Add Battle Success !";
                }
        }elseif ($_GET['do'] == 'edit'){
            if(($_POST['txt_start_vote'] >= $_POST['txt_maxvote']) || (!$_setting_battle->validateTitle($_POST['txt_title'])) || (!$_setting_battle->validateTitle($_POST['txt_subtitle'])) || (!$_setting_battle->validateStartVote($_POST['txt_start_vote'])) || (!$_setting_battle->validateMaxVote($_POST['txt_maxvote']))){
                $color = "red";
                $disable_select_type_battles = "disabled='disabled'";
                $id_edit = $_GET['id'];$id_battle_id = $_GET['id'];
                $battle_edit = $_setting_battle->getBattlesById($id_edit);
                $row_items = $_setting_battle_item->getAllBattles_item($id_battle_id);
                $input_id = '<input type="hidden" name="id" value="'.$battle_edit->id.'" />';
                $input_id_battle = '<input type="hidden" name="id_battle" value="'.$battle_edit->id.'" />';
                $input_id = "";
                $titlevalue = $_POST['txt_title'];
                $subtitlevalue = $_POST['txt_subtitle'];
                $startvotevalue = $_POST['txt_start_vote'];
                $maxvotevalue = $_POST['txt_maxvote'];
                if($_POST['active']== 'Yes') $selected_ac_yes = "selected='selected'"; else $selected_ac_no = "selected='selected'";
                if($_POST['battle_type']== 'Image') $selected_image = "selected='selected'"; else $selected_video = "selected='selected'";
                if($_POST['battle_category']=='entertainment') $selected_entertainment = "selected='selected'"; elseif($_POST['battle_category']=='music') $selected_music = "selected='selected'"; else  $selected_sport = "selected='selected'";
                if ($_GET['do'] == 'add'){ $message = "Add battle Failed !"; }else{ $message = "Edit Battle Failed !";}
                if(!$_setting_battle->validateTitle($_POST['txt_title'])){ $titleInfo = "Field must more than 3 letters!"; $class_input_title = "inp-form-error"; }
                if(!$_setting_battle->validateTitle($_POST['txt_subtitle'])){ $subtitleInfor = " Field must more than 3 letters !"; $class_input_sub = "inp-form-error"; }
                if($_POST['txt_maxvote'] <= $_POST['txt_start_vote']) {$maxvoteInfo = "Max Vote must greater than Start Vote";$startvoteInfo = "Start Vote must less than Max Vote";$class_input_code_start = "inp-form-error"; $class_input_code = "inp-form-error"; }
                if(!$_setting_battle->validateStartVote($_POST['txt_start_vote'])){ $startvoteInfo = "The start Vote must number and 1 digit !"; $class_input_code_start = "inp-form-error"; }
                if(!$_setting_battle->validateMaxVote($_POST['txt_maxvote'])){ $maxvoteInfo = "The max Vote must number and 4 digit !"; $class_input_code = "inp-form-error"; }
            }else{
                $color = "green";
                $message = "Edit Battle Success !";
                $id_edit = $_GET['id'];$id_battle_id = $_GET['id'];
                $date_update = date("Y,m,d");
                $battle = new battles($id_edit, $_POST['txt_title'], $_POST['txt_subtitle'], $_POST['battle_type'], $_POST['active'], $_POST['txt_maxvote'], $_POST['txt_start_vote'],'', $date_update,$_POST['category']);
                $_setting_battle->editBattles($battle);
                $battle_edit = $_setting_battle->getBattlesById($id_edit);
                $row_items = $_setting_battle_item->getAllBattles_item($id_battle_id);
                $titlevalue = $battle_edit->title;
                $subtitlevalue =  $battle_edit->sub_title;
                $startvotevalue = $battle_edit->vote_start_from;
        		$maxvotevalue = $battle_edit->max_vote;
                $disable_select_type_battles = "disabled='disabled'";
                $input_id = '<input type="hidden" name="id" value="'.$battle_edit->id.'" />';
                $input_id_battle = '<input type="hidden" name="id_battle" value="'.$battle_edit->id.'" />';
                if($battle_edit->running == "Yes") $selected_ac_yes = "selected='selected'"; else $selected_ac_no = "selected='selected'";
            	if($battle_edit->type =="Image") $selected_image = "selected='selected'"; else 	$selected_video = "selected='selected'";      
                if($battle_edit->category=='entertainment') $selected_entertainment = "selected='selected'"; elseif($battle_edit->category=='music') $selected_music = "selected='selected'"; else  $selected_sport = "selected='selected'";
            }  
        }      
    }else{
        $id_battle_id = $_GET['id'];
        $row_items = $_setting_battle_item->getAllBattles_item($id_battle_id);
        if ($_GET['do'] == 'edit') {
    	    $id_edit = $_GET['id'];$id_battle_id = $_GET['id'];
            $disable_select_type_battles = "disabled='disabled'";
            $battle_edit = $_setting_battle->getBattlesById($id_edit);
            $row_items = $_setting_battle_item->getAllBattles_item($id_battle_id);
            $titlevalue = $battle_edit->title;
            $subtitlevalue =  $battle_edit->sub_title;
            $startvotevalue = $battle_edit->vote_start_from;
    		$maxvotevalue = $battle_edit->max_vote;
            $input_id = '<input type="hidden" name="id" value="'.$battle_edit->id.'" />';
            $input_id_battle = '<input type="hidden" name="id_battle" value="'.$battle_edit->id.'" />';
            if($battle_edit->running == "Yes") $selected_ac_yes = "selected='selected'"; else $selected_ac_no = "selected='selected'";
        	if($battle_edit->type =="Image") $selected_image = "selected='selected'"; else 	$selected_video = "selected='selected'";
            if($battle_edit->category=='entertainment') $selected_entertainment = "selected='selected'"; elseif($battle_edit->category=='music') $selected_music = "selected='selected'"; else  $selected_sport = "selected='selected'";
    		}
        }
        if(isset($_POST['submit_add_item_video']) && $_POST['submit_add_item_video']=='submit'){
            if($_POST['titlevd']=='' || count($row_items)>2)
            {
                $width = 100;
                $color = "red";
                $message = "Add Battle Item Failed !  The Video Title is not null !";
                if(count($row_items)>2)  $message = "Add Battle Item Failed !  Add only 3 battle item!";
            }else{
            $video_up = "video_f";
            $path_video = $_setting_battle_item->upload_file_video($video_up);
            $image_thum = "image_thum";
            $image_f = $_setting_battle_item->upload_file_img($image_thum);
            $last_vote = date("Y,m,d");
            $battle_item_add = new battle_items('',$_POST['id_battle'],$_POST['titlevd'],$path_video,$image_f,$_POST['link_yt'],'',$last_vote);
            $_setting_battle_item->addBattles_item($battle_item_add);
            $message = "Add Battle Item Success !";
            $width = 100;
            $color = "green";
            $battle_edit = $_setting_battle->getBattlesById($id_edit);
            $row_items = $_setting_battle_item->getAllBattles_item($id_battle_id);
            }
        }
        if(isset ($_POST['submit_add_item_img']) && ($_POST['submit_add_item_img'] == 'submit')){
            if($_POST['title']=='' || count($row_items)>2)
            {
                $width = 100;
                $color = "red";
                $message = "Add Battle Item Failed !  The Image Title is not null !";
                if(count($row_items)>2)  $message = "Add Battle Item Failed !  Add only 3 battle item!";
            }else{
                $image_f = "image_f";
                $image_thum = "image_thum";
                $message = "Add Battle Item Success !";
                $width = 100;
                $color = "green";
                $image_f = $_setting_battle_item->upload_file_img($image_f);
                $path_th = $_setting_battle_item->upload_file_img($image_thum);
                $last_vote = date("Y,m,d");
                $battle_item_add = new battle_items('',$_POST['id_battle'],$_POST['title'],$image_f,$path_th,'','',$last_vote);
                $_setting_battle_item->addBattles_item($battle_item_add);
                $battle_edit = $_setting_battle->getBattlesById($id_edit);
                $row_items = $_setting_battle_item->getAllBattles_item($id_battle_id);
            }
       }
?>
    <div id="content-outer">
        <!-- start content -->
        <div id="content">
            <div id="page-heading"><h1><?php echo $page_heading?></h1></div>
            <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
                <tr>
                    <th rowspan="3" class="sized"><img src="../images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
                    <th class="topleft"></th>
                    <td id="tbl-border-top">&nbsp;</td>
                    <th class="topright"></th>
                    <th rowspan="3" class="sized"><img src="../images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
                </tr>
                <tr>
                    <td id="tbl-border-left"></td>
                    <td>
                        <div id="message-<?php echo $color?>">
							<table border="0" width="<?php echo $width."%"?>" cellpadding="0" cellspacing="0">
								<tr>
									<td class="<?php echo $color?>-left"><?php echo $message?></td>
									<td class="<?php echo $color?>-right">
									<a class="close-<?php echo $color?>"><img src="../images/table/icon_close_<?php echo $color?>.gif"   alt="" /></a>
									</td>
								</tr>
							</table>
						</div>  
                        <!--  start content-table-inner -->
                        <div id="content-table-inner">
                            <table border="0" width="100%" cellpadding="0" cellspacing="0">
                                <tr valign="top">
                                    <td>
                                        <form action="" method="POST" id="form_battle">
                                            <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                                <tr>
                                                    <th valign="top">Title :</th>
                                                    <?php echo $input_id; ?>
                                                    <td width="500px">
														<input name="txt_title" id="title" value="<?php echo $titlevalue ;?>" type="text" class="<?php echo $class_input_title;?>" />
														<span id="titleInfo" class="error"><?php echo $titleInfo;?></span>
													</td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Sub-Title:</th>
                                                    <td>
    													<input type="text" id="suibtitle" value="<?php echo $subtitlevalue;?>" name="txt_subtitle" class="<?php echo $class_input_sub;?>" />
    													<span id="subtitleInfor" class="error"><?php echo $subtitleInfor;?></span>
													</td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Start Voting from :</th>
                                                    <td>
                                                        <input name="txt_start_vote" id="startvote" value="<?php echo $startvotevalue;?>" type="text" class="<?php echo $class_input_code_start;?>" />
    													<span id="startvoteInfo" class="error"><?php echo $startvoteInfo;?></span>
													</td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Active :</th>
                                                    <td>
                                                        <select name="active" class="styledselect-day">
                                                            <option value="Yes" <?php echo $selected_ac_yes; ?>"> Yes </option>
                                                            <option value="No" <?php echo $selected_ac_no; ?>> No </option>
                                                        </select>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Maximum Votes :</th>
                                                    <td>
                                                        <input type="text" id="maxvote" name="txt_maxvote" value="<?php echo $maxvotevalue;?>" class="<?php echo $class_input_code;?>" />
    													<span id="maxvoteInfo" class="error"><?php echo $maxvoteInfo;?></span>
													</td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Battle Type :</th>
                                                    <td>
                                                        <select name="battle_type" id="type_battle" class="styledselect-day" style="width: 150px !important;" <?php echo $disable_select_type_battles?>>
                                                            <option value="Image" <?php echo $selected_image; ?>> Image Battle </option>
                                                            <option value="Video" <?php echo $selected_video; ?>> Video Battle </option>
                                                        </select>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <th valign="top">Battle Category :</th>
                                                    <td>
                                                        <select name="battle_category" id="battle_category" class="styledselect-day" style="width: 150px !important;" <?php echo $disable_select_type_battles?>>
                                                            <option value="entertainment" <?php echo $selected_entertainment; ?>>Entertainment</option>
                                                            <option value="music" <?php echo $selected_music; ?>>Music</option>
                                                            <option value="sport" <?php echo $selected_sport; ?>>Sport</option>
                                                        </select>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <th>&nbsp;</th>
                                                    <td valign="top">
                                                        <input type="submit" id="submit" name="submit" value="submit" class="form-submit" />
                                                        <a onclick="location='index.php?action=battles&page=<?php echo $_SESSION['page']+1?>&row=<?php echo $_SESSION['row']?>'" class="form-cancel">Cancel</a>
                                                        <input type="reset" value="" class="form-reset"  />
                                                    </td>
                                                    <td></td>
                                                </tr>
                                            </table>
                                        </form>
    <?php  if (isset($_GET['action']) && $_GET['do'] == 'edit') {    ?>
                                        <div style="padding-left: 650px;" ><h1>Add New Battles Item</h1></div>
        <?php if($battle_edit->type =="Image"){ ?>
                                        <form action="" method="POST" enctype="multipart/form-data" id="form_item_image">
                                            <table>
                                                <tr>
                                                    <th width="100px">&nbsp;<?php echo $input_id_battle ?></th>
                                                    <th class="minwidth-10">Image Title</th>
                                                    <td class="minwidth-11"><input type="text" name="title" class="inp-form" /></td>
                                                </tr>
                                                <tr>
                                                    <td >&nbsp;</td>
                                                    <th class="minwidth-10">Upload Image Files</th>
                                                    <td class="minwidth-11"><input type="file" name="image_f" class="inp-form" /></td>
                                                </tr>
                                                <tr>
                                                    <td >&nbsp;</td>
                                                     <th class="minwidth-10">Thumbnail for Facebook</th>
                                                     <td class="minwidth-11"><input type="file" name="image_thum" class="inp-form" /></td>
                                                </tr>
                                                <tr>
                                                    <td class="form_item1">&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <th>&nbsp;</th>
                                                    <td></td>
                                                    <td valign="top">
                                                        <input type="submit" name="submit_add_item_img" value="submit" class="form-submit" />
                                                        <input type="reset" value="" class="form-reset"  />
                                                    </td> 
                                                </tr>
                                            </table>
                                        </form>
        <?php }elseif($battle_edit->type =="Video"){  ?>
                                        <form action="" method="POST" enctype="multipart/form-data" id="form_item_video">
                                            <table>
                                                <tr>
                                                    <th width="100px"><?php echo $input_id_battle ?></th>
                                                    <th class="minwidth-10">Video Title</th>
                                                    <td class="minwidth-11"><input type="text" name="titlevd" class="inp-form" /></td>
                                                </tr>
                                                <tr>
                                                    <td >&nbsp;</td>                              
                                                    <th class="minwidth-10">Thumbnail for Facebook</th>
                                                    <td class="minwidth-11"><input type="file" name="image_thum" class="inp-form" /></td>
                                                </tr>
                                                 <tr>
                                                    <th width="100px">&nbsp;</th>
                                                    <th class="minwidth-10">Youtube Link</th>
                                                    <td class="minwidth-11"><input type="text" name="link_yt" class="inp-form" /></td>   
                                                </tr>
                                                <tr>
                                                    <td >&nbsp;</td>
                                                    <th class="minwidth-10">Upload Video Files</th>
                                                    <td class="minwidth-11">
                                                        <input type="hidden" name="MAX_FILE_SIZE" value="60000000" />
                                                        <input type="file" name="video_f" id="video_f" class="inp-form" />
                                                    </td>
                                                </tr>
                                                 <tr>
                                                    <td>&nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td></td>
                                                    <td></td>
                                                    <td valign="top">
                                                        <input type="submit" name="submit_add_item_video" value="submit" class="form-submit" />
                                                        <input type="reset" value="" class="form-reset"  />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="form_item1">&nbsp;</td>
                                                </tr>
                                            </table>
                                        </form>
        <?php }
                                     if(!empty ($row_items))
                                      {
                                     ?>
                                        <div id="page-heading"><h1>All Battles Item</h1></div>
                                    <?php
                                      }
                                      ?>
                                            <table>
                                     <?php
                                     if(!empty ($row_items))
                                      {
                                     ?>
                                                <tr>
                                                    
                                                    <th class="minwidth-11">Title</th>
                                                    <th class="minwidth-11">Thumbnail for Facebook</th>
                                                    <th class="minwidth-11">Files</th>
                                                    
                                                    <th class="minwidth-10">Voles</th>
                                                </tr>
                                          <?php
                                            
                                                    foreach($row_items as $row_item_bt)
                                                    {
                                           ?>
                                                <tr>
                                                    <td class="minwidth-11"><?php echo $row_item_bt->title ;?></td>
                                                    <td class="minwidth-11"><img src="../<?php if($row_item_bt->fb_theme !=""){echo $row_item_bt->fb_theme;}?>" width="100px" /> </td>
                                                  <td class="minwidth-11">
                                                        <?php 
                                                        if($battle_edit->type =="Image"){?>
                                                        <img src='../<?php echo $row_item_bt->file_name ;?>'width="100px" /> <?php 
                                                        }elseif($battle_edit->type =="Video"){ 
                                                        if($row_item_bt->yt_link != ''){
                                                        ?>
                                                     	<embed src="<?php echo $row_item_bt->yt_link; ?>" type="application/x-shockwave-flash" wmode="transparent" width="200"  height="150"></embed>
                                                      <?php 
                                                      }else{
                                                                if(strstr($row_item_bt->file_name,".wmv") or strstr($row_item_bt->file_name,".WMV")){?>
                                                                <script type="text/javascript">
                                                                AC_AX_RunContent( 'id','MediaPlayer','width','350','height','250','classid','CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95','standby','Loading Windows Media Player components...','type','application/x-oleobject','codebase','http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112','src','<?php echo "../".$row_item_bt->file_name?>','name','MediaPlayer1','autostart','True','wmode','transparent','filename1','<?php echo "../".$row_item->file_name ?>','showcontrols','True' ); //end AC code
                                                                </script><noscript><object id="MediaPlayer" width=350 height=250 classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">
                                                                <param name="filename1" value="<?php echo "../".$row_item_bt->file_name ?>">
                                                                <param name="Showcontrols" value="True">
                                                                <param name="autoStart" value="True">
                                                                <param name="wmode" value="transparent">

                                                                <embed type="application/x-mplayer2" src="<?php echo "../".$row_item_bt->file_name?>" name="MediaPlayer1" autoStart="True" wmode="transparent" width="350" height="250" ></embed>

                                                                </object></noscript>		
                                                                <?php
                                                                }
                                                                elseif(strstr($row_item_bt->file_name,".mpg") or strstr($row_item_bt->file_name,".mpeg") or strstr($row_item_bt->file_name,".MPEG") or strstr($row_item_bt->file_name,".MPG") or strstr($row_item_bt->file_name,".avi") or strstr($row_item_bt->file_name,".AVI"))
                                                                {?>
                                                                <script type="text/javascript">
                                                                AC_AX_RunContent( 'id','MediaPlayer1','classid','CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95','codebase','http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701','standby','Loading Microsoft Windows? Media Player components...','type','application/x-oleobject','width','640','height','350','pluginspage','http://www.microsoft.com/Windows/MediaPlayer/','src','<?php echo "../".$row_item_bt->file_name;?>','name','MediaPlayer1','autostart','true','showcontrols','true','volume','-450','filename1','<?php echo "../".$row_item_bt->file_name;?>','animationatstart','true','transparentatstart','true' ); //end AC code
                                                                </script><noscript><object id="MediaPlayer1" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
                                                                standby="Loading Microsoft Windows? Media Player components..." type="application/x-oleobject" width="640" height="350">
                                                                <param name="fileName1" value="<?php echo "../".$row_item_bt->file_name;?>">
                                                                <param name="animationatStart" value="true">
                                                                <param name="transparentatStart" value="true">
                                                                <param name="autoStart" value="true">
                                                                <param name="showControls" value="true">
                                                                <param name="Volume" value="-450">
                                                                <embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="<?php echo "../".$row_item_bt->file_name;?>" name="MediaPlayer1" width=350 height=250 autostart=1 showcontrols=1 volume=-450>
                                                                </object></noscript>
				
                                                          <?php }else
                                                                {
                                                                ?>
                                                              <script src='../js/AC_RunActiveContent.js' language='javascript'></script>
                                                                <!-- saved from url=(0013)about:internet -->
                                                                <script language='javascript'>
                                                                 AC_FL_RunContent('codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0', 'width', '200', 'height', '150', 'src', ((!DetectFlashVer(9, 0, 0) && DetectFlashVer(8, 0, 0)) ? '../js/OSplayer' : '../js/OSplayer'), 'pluginspage', 'http://www.macromedia.com/go/getflashplayer', 'id', 'flvPlayer', 'allowFullScreen', 'true', 'allowScriptAccess', 'always', 'movie', ((!DetectFlashVer(9, 0, 0) && DetectFlashVer(8, 0, 0)) ? '../js/OSplayer' : '../js/OSplayer'), 'FlashVars', 'movie=<?php echo "../".$row_item_bt->file_name;?>&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=off&vTitle=Super Mario Brothers Lego Edition&showTitle=yes');
                                                                </script>
                                                                <noscript>
                                                                 <object width='200' height='150' id='flvPlayer'>
                                                                  <param name='allowFullScreen' value='true'>
                                                                   <param name="allowScriptAccess" value="always"> 
                                                                  <param name='movie' value='../js/OSplayer.swf?movie=<?php echo "../".$row_item_bt->file_name;?>&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=off&vTitle=Super Mario Brothers Lego Edition&showTitle=yes'>
                                                                  <embed src='../js/OSplayer.swf?movie=<?php echo "../".$row_item_bt->file_name;?>&btncolor=0x333333&accentcolor=0x31b8e9&txtcolor=0xdddddd&volume=30&autoload=on&autoplay=off&vTitle=Super Mario Brothers Lego Edition&showTitle=yes' width='200' height='150' allowFullScreen='true' type='application/x-shockwave-flash' allowScriptAccess='always'>
                                                                 </object>
                                                                </noscript>
                                                    <?php
                                                                }
                                                            ?>
                                                            
                                                        <?php
                                                            }
                                                        }
                                                        ?> 
                                                         </td>
                                                    <td class ="minwidth-11"><?php echo $row_item_bt->votes; ?></td>
                                                    <td>                                             
                                                        <a title="Delete" onClick="location='index.php?action=battles&do=edit&id=<?php echo $_GET['id'];?>&do_item=del_item&id_bt=<?php echo $row_item_bt->id; ?>'" class="icon-2 info-tooltip"></a>
                                                    </td>
                                                </tr>
                                          <?php
                                                    }
                                            }
                                          ?>
                                                <tr>
                                                    <td class="form_item1">&nbsp;</td>
                                                </tr>
                                            </table>
                                        <!-- end id-form  -->
                                    </td>
        <?php } ?>
                                </tr>
                                <tr>
                                    <td><img src="../images/shared/blank.gif" width="695" height="1" alt="blank" /></td>
                                </tr>
                            </table>
                            <div class="clear"></div>
                        </div>
                        <!--  end content-table-inner  -->
                    </td>
                    <td id="tbl-border-right"></td>
                </tr>
                <tr>
                    <th class="sized bottomleft"></th>
                    <td id="tbl-border-bottom">&nbsp;</td>
                    <th class="sized bottomright"></th>
                </tr>
            </table>
            <div class="clear">&nbsp;</div>
        </div>
        <!--  end content -->
        <div class="clear">&nbsp;</div>
<?php  } else {   
            $_SESSION['page']=$_GET['page']-1;
            $_SESSION['row']=$_GET['row'];
?>
    <div id="content-outer">
        <!-- start content -->
        <div id="content">
            <div id="top-search">
                <form action="index.php?<?php echo $_SERVER["QUERY_STRING"]; ?>" method="POST">
                    <table border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td><input type="text" name="txt_search" onBlur="if (this.value=='') { this.value='Search'; }" onFocus="if (this.value=='Search') { this.value=''; }" class="top-search-inp" /></td>
                            <td>
                                    <input type="submit" value="Search" class="bottom_search" name="search"  src="../images/shared/top_search_btn.gif"  />
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
            <!--  start page-heading -->
            <div id="page-heading">
                <h1><a style="color: #2e74b2; cursor: pointer;" onClick="location='index.php?action=battles&do=add'">Add New Battles</a></h1>
            </div>
            <!-- end page-heading -->

            <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
                <tr>
                    <th rowspan="3" class="sized"><img src="../images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
                    <th class="topleft"></th>
                    <td id="tbl-border-top">&nbsp;</td>
                    <th class="topright"></th>
                    <th rowspan="3" class="sized"><img src="../images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
                </tr>
                <tr>
                    <td id="tbl-border-left"></td>
                    <td>
                        <!--  start content-table-inner ...................................................................... START -->
                        <div id="content-table-inner">
                            <!--  start table-content  -->
                            <div id="table-content">
                                <!--  start product-table ..................................................................................... -->
                                <form id="mainform" action="">
                                    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
                                        <tr>
                                            <th class="table-header-check"><a id="toggle-all" ></a> </th>
                                            <th class="table-header-repeat line-left minwidth-1"><a href="">Title </a>	</th>
                                            <th class="table-header-repeat line-left minwidth-1"><a href="">Battle Type </a></th>
                                            <th class="table-header-repeat line-left minwidth-12"><a href="">Battle Category</a></th>
                                            <th class="table-header-repeat line-left minwidth-12"><a href="">Created On </a></th>
                                            <th class="table-header-repeat line-left minwidth-12"><a href="">Last Updated </a></th>
                                            <th class="table-header-repeat line-left minwidth-13"><a href="">Active </a></th>
                                            <th class="table-header-repeat line-left minwidth-13"><a href="">Max Votes </a></th>
                                            <th class="table-header-repeat line-left minwidth-1"><a href="">Started From </a></th>
                                            <th class="table-header-repeat line-left minwidth-13"><a href="">Total Votes </a></th>
                                            <th class="table-header-options line-left"><a href="">Options</a></th>
                                        </tr>
                    <?php
                        $page = $_GET['page']-1;
                        $row = $_GET['row'];
                        $lastpage = (int)(($_setting_battle->countPageBattle()-1)/$_GET['row'])+1;
                        if($page>=$lastpage) header("Location:../backend/index.php?action=battles&page=1&row=".$row);
                        $stus = $_setting_battle->pagingBattle($page,$_GET['row']);
                        foreach ($stus as $stusk) {
                    ?>
                                            <form action="" method="POST">
                                                <tr>
                                                    <td><input type="hidden" name="id" value="<?php echo $stusk->id; ?>"><input  type="checkbox"/></td>
                                                    <td><?php echo $stusk->title; ?></td>
                                                    <td><?php echo $stusk->type . ' Battle'; ?></td>
                                                    <td><?php echo $stusk->category; ?></td>
                                                    <td><?php echo date("d M, Y", strtotime($stusk->date_created)); ?></td>
                                                    <td><?php echo date("d M, Y", strtotime($stusk->last_update)); ?></td>
                                                    <td><?php echo $stusk->running; ?></td>
                                                    <td><?php echo $stusk->max_vote; ?></td>
                                                    <td><?php echo $stusk->vote_start_from; ?></td>
                                                    <td><?php echo $_setting_battle->totalVotes($stusk->id); ?></td>
                                                    <td>
                                                        <a title="Edit" onClick="location='index.php?action=battles&do=edit&id=<?php echo $stusk->id; ?>'" class="icon-1 info-tooltip"></a>
                                                        <a title="Delete" onClick="location='index.php?action=battles&do=del&id=<?php echo $stusk->id; ?>&page=<?php echo $page+1?>&row=<?php echo $row?>'" class="icon-2 info-tooltip"></a>
                                                    </td>
                                                </tr> 
                                            </form>
                    <?php } ?>
                                    </table>
                                    <!--  end product-table................................... --> 
                                </form>
                            </div>
                            <table border="0" cellpadding="0" cellspacing="0" id="paging-table">
                                <tr>
                                    <td>
                                        <a onclick="location='index.php?action=battles&page=1&row=<?php echo $row?>'" class="page-far-left"></a>
        								<a onclick="location='index.php?action=battles&page=<?php if($page>0) echo $page; else echo 1;?>&row=<?php echo $row?>'" class="page-left"></a>
        								<div id="page-info">Page <strong id="page-current"><?php echo $page+1 ?></strong> / <?php echo $lastpage;?></div>
        								<a onclick="location='index.php?action=battles&page=<?php if($page+2<$lastpage) echo $page+2; else echo $lastpage;?>&row=<?php echo $row?>'" class="page-right"></a>
        								<a onclick="location='index.php?action=battles&page=<?php echo $lastpage;?>&row=<?php echo $row?>'" class="page-far-right"></a>
                                    </td>
                                    <td>
                                        <select  class="styledselect_pages">
                                            <option value="">Number of rows</option>
                                            <option value="">5</option>
                                            <option value="">10</option>
                                            <option value="">15</option>
                                        </select>
                                    </td>
                                </tr>
                            </table>
                            <!--  end paging................ -->
                            <div class="clear"></div>
                        </div>
                        <!--  end content-table-inner ............................................END  -->
                    </td>
                    <td id="tbl-border-right"></td>
                </tr>
            </table>
            <div class="clear">&nbsp;</div>
        </div>
        <!--  end content -->
        <div class="clear">&nbsp;</div>
    </div>
    <?php
}
?>
<script type="text/javascript" src="../js/validbattle.js" ></script>